class Solution {
public:
    long long prev = LLONG_MIN;

    bool isValidBST(TreeNode* root) {

        if(root == nullptr) return true;
        bool lhs = isValidBST(root->left);

        if(root->val > prev)      
            prev = root->val;     
        else
            return false;

        bool rhs = isValidBST(root->right);
        return lhs && rhs;
    }
};